package com.shir.travels.ui.zhoubian;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.shir.travels.R;
import com.shir.travels.ui.tuisong.TuisongRecyclerAdapter;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

public class ZhouBian extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<Integer> imageResources;
    private List<String> comments;
    private List<String> descs;

    private void initData() {
        imageResources = new ArrayList<>();
        comments = new ArrayList<>();
        descs = new ArrayList<>();
        imageResources.add(R.drawable.scene_xinshi_town);
        imageResources.add(R.drawable.scene_sword_pool);
        imageResources.add(R.drawable.scene_moganshan);
        comments.add(getResources().getString(R.string.scene_xinshiguzhen_short));
        comments.add(getResources().getString(R.string.scene_jianchi_short));
        comments.add(getResources().getString(R.string.scene_moganshan_short));
        descs.add(getResources().getString(R.string.scene_xinshiguzhen));
        descs.add(getResources().getString(R.string.scene_jianchi));
        descs.add(getResources().getString(R.string.scene_moganshan));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhoubian);
        initData();
        recyclerView = (RecyclerView) findViewById(R.id.recycle_view_zhoubian);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        ZhoubianRecyclereAdapter adapter = new ZhoubianRecyclereAdapter(imageResources, comments);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new ZhoubianRecyclereAdapter.OnItemClickListener() {
            @Override
            public void onClick(View view, int position) {
                Intent intent = new Intent();
                intent.putExtra(ZhouBianDesc.INTENT_TITLE, comments.get(position));
                intent.putExtra(ZhouBianDesc.INTENT_IMG_RES, String.valueOf(imageResources.get(position)));
                intent.putExtra(ZhouBianDesc.INTENT_DESC, descs.get(position));
                intent.setClass(ZhouBian.this, ZhouBianDesc.class);
                startActivity(intent);
            }
        });

        CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapsing_toolbar_zhoubian);
        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar_zhoubian);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }

        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        toolbar.setTitleTextAppearance(this,R.style.Toolbar_TitleText);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        getSupportActionBar().setDisplayShowTitleEnabled(false);

    }
}
